<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="${column.comments}" prop="orderNo">
      <el-input v-model="dataForm.orderNo" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="proposalId">
      <el-input v-model="dataForm.proposalId" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="proposalNo">
      <el-input v-model="dataForm.proposalNo" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="productId">
      <el-input v-model="dataForm.productId" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="productName">
      <el-input v-model="dataForm.productName" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="orderPrice">
      <el-input v-model="dataForm.orderPrice" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="caseName">
      <el-input v-model="dataForm.caseName" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="casePrice">
      <el-input v-model="dataForm.casePrice" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="createPersonId">
      <el-input v-model="dataForm.createPersonId" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="telephone">
      <el-input v-model="dataForm.telephone" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="cardId">
      <el-input v-model="dataForm.cardId" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="updateTime">
      <el-input v-model="dataForm.updateTime" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="payType">
      <el-input v-model="dataForm.payType" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="payTime">
      <el-input v-model="dataForm.payTime" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="transactionId">
      <el-input v-model="dataForm.transactionId" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="serialNumber">
      <el-input v-model="dataForm.serialNumber" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="sign">
      <el-input v-model="dataForm.sign" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="excelLogId">
      <el-input v-model="dataForm.excelLogId" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="appId">
      <el-input v-model="dataForm.appId" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="orderState">
      <el-input v-model="dataForm.orderState" placeholder="${column.comments}"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          orderId: 0,
          orderNo: '',
          proposalId: '',
          proposalNo: '',
          productId: '',
          productName: '',
          orderPrice: '',
          caseName: '',
          casePrice: '',
          createTime: '',
          createPersonId: '',
          telephone: '',
          cardId: '',
          updateTime: '',
          payType: '',
          payTime: '',
          transactionId: '',
          serialNumber: '',
          sign: '',
          excelLogId: '',
          appId: '',
          orderState: ''
        },
        dataRule: {
          orderNo: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          proposalId: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          proposalNo: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          productId: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          productName: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          orderPrice: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          caseName: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          casePrice: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          createPersonId: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          telephone: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          cardId: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          payType: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          payTime: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          transactionId: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          serialNumber: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          sign: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          excelLogId: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          appId: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          orderState: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.orderId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.orderId) {
            this.$http({
              url: this.$http.adornUrl(`/order/order/info/${this.dataForm.orderId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.orderNo = data.order.orderNo
                this.dataForm.proposalId = data.order.proposalId
                this.dataForm.proposalNo = data.order.proposalNo
                this.dataForm.productId = data.order.productId
                this.dataForm.productName = data.order.productName
                this.dataForm.orderPrice = data.order.orderPrice
                this.dataForm.caseName = data.order.caseName
                this.dataForm.casePrice = data.order.casePrice
                this.dataForm.createTime = data.order.createTime
                this.dataForm.createPersonId = data.order.createPersonId
                this.dataForm.telephone = data.order.telephone
                this.dataForm.cardId = data.order.cardId
                this.dataForm.updateTime = data.order.updateTime
                this.dataForm.payType = data.order.payType
                this.dataForm.payTime = data.order.payTime
                this.dataForm.transactionId = data.order.transactionId
                this.dataForm.serialNumber = data.order.serialNumber
                this.dataForm.sign = data.order.sign
                this.dataForm.excelLogId = data.order.excelLogId
                this.dataForm.appId = data.order.appId
                this.dataForm.orderState = data.order.orderState
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/order/order/${!this.dataForm.orderId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'orderId': this.dataForm.orderId || undefined,
                'orderNo': this.dataForm.orderNo,
                'proposalId': this.dataForm.proposalId,
                'proposalNo': this.dataForm.proposalNo,
                'productId': this.dataForm.productId,
                'productName': this.dataForm.productName,
                'orderPrice': this.dataForm.orderPrice,
                'caseName': this.dataForm.caseName,
                'casePrice': this.dataForm.casePrice,
                'createTime': this.dataForm.createTime,
                'createPersonId': this.dataForm.createPersonId,
                'telephone': this.dataForm.telephone,
                'cardId': this.dataForm.cardId,
                'updateTime': this.dataForm.updateTime,
                'payType': this.dataForm.payType,
                'payTime': this.dataForm.payTime,
                'transactionId': this.dataForm.transactionId,
                'serialNumber': this.dataForm.serialNumber,
                'sign': this.dataForm.sign,
                'excelLogId': this.dataForm.excelLogId,
                'appId': this.dataForm.appId,
                'orderState': this.dataForm.orderState
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
